#!/bin/bash

green='\e[32m'
red='\e[31m'
defult='\e[39m'
bold='\e[1m'
string1='------------------------------'
string2='       	'

local_time=`date`
login_users=`who | wc -l`
login_who=`who | tr -s ' '`
procs=`ps aux | wc -l`
cpu_load=`cat /proc/loadavg | tr -s ' ' | cut -d' ' -f3`
memory_free=$(((`cat /proc/meminfo | grep "MemAva" | tr -s ' ' | cut -d' ' -f2`)/1000000))
memory_total=$(((`cat /proc/meminfo | grep "MemTo" | tr -s ' ' | cut -d' ' -f2`)/1000000))
disk_free=`df -h / | grep "/$" | tr -s ' ' | cut -d' ' -f4`
disk_total=`df -h / | grep "/$" | tr -s ' ' | cut -d' ' -f2`
ip_address=`ifconfig ens33 | grep netmask | tr -s ' ' | cut -d' ' -f3`

echo -e "\n\n$red $string1 Computer Status $string1\n\n"
echo -e "$green Time:\n$string2 $defult $local_time\n"
echo -e "$green Login Users:\n$string2 $defult $login_users users have login,there are:\n"
echo -e "$string2 $defult $login_who\n"
echo -e "$green Process in Running:\n$string2 $defult There are $procs proces is in running\n"
echo -e "$green CPU Load:\n$string2 $defult $cpu_load\n"
echo -e "$green Memory Information:\n$string2 $defult $memory_free"G" free of $memory_total"G"\n"
echo -e "$green Disk Information:\n$string2 $defult $disk_free free of $disk_total\n"

[ $memory_free -lt 1 ] && echo -e "\n$string2 $red $blod !!!!!!Free Memory Is Not Enough!!!!!!\n"\
&& echo -e "\n$string2 $red $blod ONLY $memory_free"G" IS FREE\n"

cpu_status=`echo "$cpu_load > 4" | bc`
[ $cpu_status -eq 1 ] && echo -e "\n$string@ $red $blod !!!!!!CPU Load Too Hight!!!!!!"\
&& echo -e "\n$string2 $red $blod CPU LOAD $cpu_load ON $ip_addresss\n"

disk_free_n=`echo $disk_free | cut -d'G' -f1`
[ $disk_free_n -lt 5 ] && echo -e "\n$string2 $red $blod !!!!!!Free Disk Is Not Enough!!!!!!\n"\
&& echo -e "\n$string2 $red $blod ONLY $disk_free"G" IS FREE\n"

[ $memory_free -lt 2 ] && echo -e "\n$string2 $red $blod !!!!!!Free Memory Is Not Enough!!!!!!\n"\
&& echo -e "\n$string2 $red $blod ONLY $memory_free"G" IS FREE\n"